package com.hyh.shipment.config;

import com.hyh.shipment.constants.PayConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {

    // 声明topic的交换机
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(PayConstants.PAY_EXCHANGE, true, false);
    }

    // 声明队列
    @Bean
    public Queue payQueue(){
        return new Queue(PayConstants.PAY_QUEUE,true);
    }

    // 绑定队列和交换机
    @Bean
    public Binding Updatebinding(){
        return BindingBuilder
                .bind(payQueue())
                .to(topicExchange())
                .with(PayConstants.PAY_ROUTING_KEY);
    }
}
